//  多态
#include <iostream>

using namespace std;

class Shape
{
private:
  /* data */
public:
  int w, h;
  Shape(int x, int y);
  ~Shape();
  int get_area()
  {
    cout << "Parent class area :" << endl;
    return 0;
  }; // 定义
};

Shape::Shape(int x, int y)
{
  w = x;
  h = y;
  cout << "Shape: call 构造函数" << endl;
}

Shape::~Shape()
{
  cout << "Shape: call 析构函数" << endl;
}

class Rect : public Shape
{
private:
  /* data */
public:
  Rect(int x, int y);
  ~Rect();
  int get_area()
  {
    return w * h;
  }
};

Rect::Rect(int x, int y) : Shape(x, y) // NOTE: 调用父类的构造函数
{
  cout << "Rect: call 构造函数" << endl;
}

Rect::~Rect()
{
  cout << "Rect: call 构造函数" << endl;
}

int main(int argc, char const *argv[])
{
  Rect r(10, 20);
  cout << "Rect call get_area " << r.get_area() << endl;
  return 0;
}
